package com.itheima.springboottlias.controller;

import Pojo.Clazz;
import Pojo.ClazzQueryParam;
import Pojo.PageResult;
import Pojo.Result;
import com.itheima.springboottlias.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RequestMapping("/clazzs")
@RestController
@Slf4j
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    // 添加班级
    @PostMapping
    public Result addClass(@RequestBody Clazz clazz) {
       clazzService.addClass(clazz);
        return Result.success();
    }
    // 查询所有班级
    @GetMapping("/list")
    public Result queryAll() {
        return Result.success(clazzService.queryAll());
    }
    // 分页和条件查询班级
    @GetMapping()
    public Result query(ClazzQueryParam clazzQueryParam){
        PageResult pageResult = clazzService.queryByCondition(clazzQueryParam);
        return Result.success(pageResult);
    }
    // 删除根据id班级
    @DeleteMapping("/{id}")
    public Result removeById(@PathVariable Integer id) {
        clazzService.removeById(id);
        return Result.success();
    }
    //根据id查询班级
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id) {
        Clazz clazz = clazzService.findById(id);
        return Result.success(clazz);
    }
    // 修改班级
    @PutMapping
    public Result update(@RequestBody Clazz clazz) {
        log.info("接收到的请求参数："+clazz);
        clazzService.updateClass(clazz);
        return Result.success();
    }

}
